import http from '../../../common/httpUtil';
import * as types from './organBaoMutationTypes';

const actions = {
  queryOrganBao ({commit}, {pageIndex = 1, pageSize = 10} = {}) {
    commit(types.ORGAN_BAO_QUERY_BEGIN)
    return http.getRaw(`admin/organ/getOrganBabies?pageIndex=${pageIndex}&pageSize=${pageSize}`).then(data => {
      console.log(data)
      commit(types.ORGAN_BAO_QUERY_SUC, {organBao: data.data.result})
      commit(types.ORGAN_BAO_QUERY_COUNT_SUC, {totalCount: data.data.totalCount})
    })
  },
  queryOnlineOrganBao ({commit}) {
    commit(types.ONLINE_ORGAN_BAO_QUERY_BEGIN)
    return http.getRaw(`admin/organ/getOnline`).then(data => {
      console.log(data)
      commit(types.ONLINE_ORGAN_BAO_QUERY_SUC, {onlineOrganBao: data.data.result})
    })
  },
  editRecommend ({commit}, {fundCode}) {

    return http.getRaw(`admin/organ/setRecommend?fundCode=${fundCode}`).then(data => {
      console.log(data)
      commit(types.SYS_RECOMMENDS_UPLOAD_UPDATE_SUC, {fundCode})
    })
  },
  editOrganBao ({commit}, formData) {
    return http.post(`admin/organ/edit/organBaby`, formData).then(data => {
      console.log(data)
      commit(types.ORGAN_BAO_UPLOAD_UPDATE_SUC, {formData})
      return data
    })
  },
  addOrganBao ({commit}, formData) {
    return http.post(`admin/organ/edit/organBaby`, formData).then(data => {
      console.log(data)
      commit(types.ORGAN_BAO_UPLOAD_ADD_SUC, {formData})
      return data
    })
  },
  online ({commit}, {fundCode, state}) {
    return http.getRaw(`admin/organ/isValid?fundCode=${fundCode}&state=${state}`).then(data => {
      console.log(data)
      commit(types.ORGAN_BAO_ONLINE_SUC, {fundCode})
      return data
    })
  }

};


export default actions;
